package com.itheima.consumer.message;

import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

@Component
public class Message {

    // Direct
    @RabbitListener(queues = "myQueue")
    public void receiveDirectMessage(String message) {
        System.out.println(" [x] Received '" + message + "'");
    }

    // Fanout
    @RabbitListener(queues = "queue1")
    public void receiveMessageFromQueue1(String message) {
        System.out.println("Queue1 [x] Received '" + message + "'");
    }

    @RabbitListener(queues = "queue2")
    public void receiveMessageFromQueue2(String message) {
        System.out.println("Queue2 [x] Received '" + message + "'");
    }

    // Topic
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "queue1", durable = "true"),
            exchange = @Exchange(value = "topicExchange", type = "topic"),
            key = "item.*"))
    public void receiveMessageFromQueue11(String message) {
        System.out.println("Queue1 [x] Received '" + message + "'");
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "queue2", durable = "true"),
            exchange = @Exchange(value = "topicExchange", type = "topic"),
            key = "#.update"))
    public void receiveMessageFromQueue21(String message) {
        System.out.println("Queue2 [x] Received '" + message + "'");
    }

    // header

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "queue6", durable = "true"),
            exchange = @Exchange(value = "headersExchange", type = "headers"),
            arguments = {
                    @Argument(name = "type", value = "info"),
                    @Argument(name = "format", value = "json")
            }))
    public void receiveMessageHeaderFromQueue1(String message) {
        System.out.println("Queue1 [x] Received '" + message + "'");
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "queue7", durable = "true"),
            exchange = @Exchange(value = "headersExchange", type = "headers"),
            arguments = {
                    @Argument(name = "type", value = "error")
            }))
    public void receiveMessageHeaderFromQueue2(String message) {
        System.out.println("Queue2 [x] Received '" + message + "'");
    }


}
